package com.example.controller.seller;

import com.example.dto.ImportOrderDto;
import com.example.service.OrderService;
import com.example.util.ExcelUtil;
import com.example.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author 朽
 */
@RestController
@Slf4j
@RequestMapping("/seller/import")
public class ImportOrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/GetExcel")
    public Result<String> GetExcel(@RequestParam("file") MultipartFile file) throws Exception {
        List<ImportOrderDto> testDtos = ExcelUtil.readMultipartFile(file);
        for (ImportOrderDto testDto : testDtos) {
            orderService.updateOrder(testDto);
        }
        return Result.ok("导入成功");
    }
}
